游标删除多个表里脏数据的方法
end
as第二种方法:
declare @table_name varchar(50)
declare @sql nvarchar(500)--此处要注意,声明的长度一定要够
delete from projectrangtree where type=4 and parentid not in(select id from projectrangtree where type=3)
select table_name from section_type
--删除section_settings的脏数据
declare del_cursor cursor scroll for
delete from projectrangtree where deleteversion>0
close del_cursor
while (@@fetch_status=0)
--print @table_name
delete from section_settings where parent_prj_tree_id not in(select id from projectrangtree)
复制代码 代码如下:
--begin
--declare @id int
set @Sql = N'delete from '+@tableName--delete from (select talbe_name from section_type) where measuring_point_id not in (select id from measuring_point_setting)
--delete from @table_name where measuring_point_id not in (select id from measuring_point_setting)
--print @table_name
WHILE(@@FETCH_STATUS = 0)
--deallocate test_cursor
Fetch Next From curTable Into @tableName--删除projectrangtree的脏数据
--print @id
Fetch Next From curTable Into @tableName
复制代码 代码如下:
--while @@fetch_status=0
for select Table_Name from information_schema.tables where TABLE_TYPE='BASE TABLE'BEGIN
--declare @table_name nvarchar(50)
--close test_cursor
begin
--print quotename(@table_name)
--end
CREATE proc [dbo].[delAllRecord]
--删除各个表里的测点
Open curTable--open test_cursor
--select id,table_name from dbo.section_type
declare @tableName nvarchar(255)--fetch next from test_cursor into @id,@table_name
--exec sp_executesql @measuring_point_id
CLOSE curTableDEALLOCATE curTable exec sp_executesql @sql
open del_cursor
enddelete from projectrangtree where type=5 and parentid not in(select id from projectrangtree where type=4)
fetch next from del_cursor into @table_name
set @sql = 'delete from '+ quotename(@table_name) +' where measuring_point_id not in(select id from measuring_point_setting)'
delete from projectrangtree where type=3 and parentid not in(select id from projectrangtree where type=2)
--set @measuring_point_id='select measuring_point_id from '+quotename(@table_name)
deallocate del_cursor
exec sp_executesql @sql
--declare @measuring_point_id nvarchar(500)
declare @Sql nvarchar(255)--declare test_cursor cursor scroll forDeclare curTable Cursor
fetch next from del_cursor into @table_name
相关热词: 方法
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/sql/mssql/2980.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
SQL基本教程之行转列Pivo
时间:2021-01-20
-
region from hr.Employees union
时间:2021-01-20
-
有时候需要调整用户权限
时间:2021-01-19
-
(但使用 ORDER BY 子句并不
时间:2021-01-19
-
RAND()*10000)insert into Detail
时间:2021-01-19
-
OR 运算符:在两侧的查询
时间:2021-01-19
-
放假之前老大跟我提起了
时间:2021-01-19
-
数据库的运维计策剧本篇
时间:2021-01-19
热门文章
-
4.与聚合函数和 GROUP BY 子句有关的常见错
时间:2021-01-19
-
SQL Server安全(11/11):审核(Auditing)
时间:2021-01-09
-
sqlserver中查询横表变竖表的sql语句简析
时间:2020-12-08
-
SQL Server简单模式下误删除堆表记录恢复方
时间:2020-12-12
-
关于SQL Server查询语句的使用
时间:2020-12-13
-
MSSQL教程_mssql数据库教程_MSSQL基础教程_第
时间:2020-12-13
-
jdbc连接sql server数据库问题分析
时间:2020-12-10
-
详解SQL游标的用法
时间:2020-12-27
-
sql server 关于设置null的一些建议
时间:2020-12-28
-
mssql关于一个表格结构的另外一种显示(表
时间:2020-12-11
